﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
public partial class UserControl_Menu_TopMenuVertical : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblMes.Text = TopMenuCountry();

    }

    private string TopMenuCountry()
    {

        StringBuilder menu = new StringBuilder();
        menu.Append("<ul class=\"sf-menu\">");
        //Home
        menu.Append("<li class=\"current\" id=\"menu-item-home\">");
        menu.Append("<a href=\"Default.aspx\"></a>");
        menu.Append("</li>");
        //Gioi Thieu
        menu.Append("<li class=\"current\" id=\"menu-item-intro\">");
        menu.Append("<a href=\"GioiThieu.aspx\"></a>");

        menu.Append("</li>");
        //San pham
        menu.Append("<li class=\"current\" id=\"menu-item-product\">");
        menu.Append("<a href=\"DanhSach.aspx\"></a>");
        menu.Append("<ul>");
        menu.Append(TopMenuCategory("sp"));
        menu.Append("</ul>");
        menu.Append("</li>");
        //Dich vu
        menu.Append("<li class=\"current\" id=\"menu-item-service\">");
        menu.Append("<a href=\"DichVu.aspx\"></a>");
        menu.Append("<ul>");
        menu.Append(TopMenuCategory("dv"));
        menu.Append("</ul>");
        menu.Append("</li>");
        //Tin tuc
        menu.Append("<li class=\"current\" id=\"menu-item-news\">");
        menu.Append("<a href=\"TinTuc.aspx\"></a>");
        menu.Append("<ul>");
        menu.Append(TopMenuCategory("tt"));
        menu.Append("</ul>");
        menu.Append("</li>");
        //Lien he
        menu.Append("<li class=\"current\" id=\"menu-item-contact\">");
        menu.Append("<a href=\"LienHe.aspx\"></a>");

        menu.Append("</li>");
        menu.Append("</ul>");
        return menu.ToString();
    }
    private string TopMenuCategory(string table)
    {
        string sql = "";
        StringBuilder menu = new StringBuilder();
        if (table.Equals("sp"))
        {
            sql = "SELECT id,Tenloai FROM loai";
            clsBSDungChung bs = new clsBSDungChung();
            DataTable tbCat = new DataTable();
            tbCat = bs.GetDataTableSQL(sql, "Cate");
            for (int i = 0; i < tbCat.Rows.Count; i++)
            {
                menu.Append("<li class=\"current\">");
                menu.Append("<a href=\"DanhSach.aspx?Loaiid=" + tbCat.Rows[i][0].ToString() + "\">" + tbCat.Rows[i][1].ToString() + "</a>");
                menu.Append("</li>");
            }
        }
        else
        {
            if (table.Equals("dv"))
            {
                sql = "SELECT tintuc.id,tintuc.tieude FROM tintuc,loaitin where tintuc.loaitin=loaitin.id and loaitin.theloai=1";
                clsBSDungChung bs = new clsBSDungChung();
                DataTable tbCat = new DataTable();
                tbCat = bs.GetDataTableSQL(sql, "Cate");
                for (int i = 0; i < tbCat.Rows.Count; i++)
                {
                    menu.Append("<li class=\"current\">");
                    menu.Append("<a href=\"DichVu.aspx?id=" + tbCat.Rows[i][0].ToString() + "\">" + tbCat.Rows[i][1].ToString() + "</a>");
                    menu.Append("</li>");
                }
            }
            else
            {
                if (table.Equals("tt"))
                {
                    sql = "SELECT loaitin.id,loaitin.tieude FROM loaitin where loaitin.theloai=2";
                    clsBSDungChung bs = new clsBSDungChung();
                    DataTable tbCat = new DataTable();
                    tbCat = bs.GetDataTableSQL(sql, "Cate");
                    for (int i = 0; i < tbCat.Rows.Count; i++)
                    {
                        menu.Append("<li class=\"current\">");
                        menu.Append("<a href=\"Tintuc.aspx?Cateid=" + tbCat.Rows[i][0].ToString() + "\">" + tbCat.Rows[i][1].ToString() + "</a>");
                        menu.Append("</li>");
                    }
                }
            }
        }

        return menu.ToString();
    }

}
